﻿package com.wly.ui
{
	import com.wly.adapter.ItemGridAdapter;
	import com.wly.adapter.ToolbarAdapter;
	import com.wly.ui.common.SpriteObject;
	
	import flash.display.SimpleButton;
	import flash.events.MouseEvent;
	
	public class ToolBar extends SpriteObject
	{
		private var _btnPreItem:SimpleButton;
		private var _btnPrePage:SimpleButton;
		private var _btnNextItem:SimpleButton;
		private var _btnNextPage:SimpleButton;
		private var _mcItemGrid:ItemGrid;
		
		public function ToolBar()
		{
			super();
			initChilds();
		}
		
		private function initChilds():void
		{
			_btnPreItem   = getChildByName("btnPreItem") as SimpleButton;
			_btnPrePage   = getChildByName("btnPrePage") as SimpleButton;
			_btnNextItem  = getChildByName("btnNextItem") as SimpleButton;
			_btnNextPage  = getChildByName("btnNextPage") as SimpleButton;
			_mcItemGrid   = getChildByName("mcItemGrid") as ItemGrid;
			
			_btnPreItem.addEventListener(MouseEvent.CLICK, onPreItem);
			_btnPrePage.addEventListener(MouseEvent.CLICK, onPrePage);
			_btnNextItem.addEventListener(MouseEvent.CLICK, onNextItem);
			_btnNextPage.addEventListener(MouseEvent.CLICK, onNextPage);
		}
		
		protected function get toolbarAdapter():ToolbarAdapter
		{
			return adapter as ToolbarAdapter;
		}
		
		public function updateItemGridAdapter(adpt:ItemGridAdapter):void
		{
			_mcItemGrid.attachAdapter(adpt);
		}
		
		private function onPreItem(e:MouseEvent):void
		{
			if(toolbarAdapter)
			{
				toolbarAdapter.onPreItem();
			}
		}
		
		private function onPrePage(e:MouseEvent):void
		{
			if(toolbarAdapter)
			{
				toolbarAdapter.onPrePage();
			}
		}
		
		private function onNextItem(e:MouseEvent):void
		{
			if(toolbarAdapter)
			{
				toolbarAdapter.onNextItem();
			}
		}
		
		private function onNextPage(e:MouseEvent):void
		{
			if(toolbarAdapter)
			{
				toolbarAdapter.onNextPage();
			}
		}
	}
}